home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_004 / kermit / connect.c next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  102 lines

  1. /*    @(#)connect.c    1.1    1/26/85    */
  2.  
  3. #include "kermit.h"
  4. #include "errors.h"
  5.  
  6. static VOID HostIn ();
  7. static VOID HostOut ();
  8.  
  9. /*
  10.  *    Connect  establishes a virtual terminal connection
  11.  *    with the remote machine, over a tty line.
  12.  *
  13.  */
  14.  
  15. VOID Connect ()
  16. {
  17. #ifndef AMIGA
  18.     register int child_pid;
  19.     register FILE *fp;
  20. #endif
  21.  
  22.     DBUG_ENTER ("Connect");
  23. #ifdef AMIGA
  24.     Error (NOCONNECT);
  25. #else
  26.     fp = NULL;
  27.     if (!host) {
  28.     Error (CONNECT);
  29.     } else {
  30.     if (photo != NULL) {
  31.         fp = fopen (photo, "w");
  32.         if (fp == NULL) {
  33.         Error (PHOTO, photo);
  34.         }
  35.     }
  36.     child_pid = fork ();
  37.     if (child_pid) {
  38.         HostOut ();
  39.         (VOID) kill (child_pid, 9);
  40.         if (fp != NULL) {
  41.         (VOID) fclose (fp);
  42.         }
  43.     } else {
  44.         HostIn (fp);
  45.     }
  46.     }
  47. #endif    /* AMIGA */
  48.     DBUG_VOID_RETURN;
  49. }
  50.  
  51.  
  52. /*
  53.  *    We are the child process, so read from remote and send
  54.  *    to user until killed by parent when disconnecting.
  55.  *    Note infinite loop.
  56.  *
  57.  */
  58.  
  59. static VOID HostIn (fp)
  60. FILE *fp;
  61. {
  62.     auto char c;
  63.  
  64.     c = NULL;
  65.     while (TRUE) {
  66.     (VOID) read (remfd, &c, 1);
  67.     c &= 0177;        /* No 8 bit */
  68.     if (c != '\000') {
  69.         (VOID) write (1, &c, 1);
  70.     }
  71.     if (fp != NULL) {
  72.         (VOID) putc (c, fp);
  73.         (VOID) fflush (fp);
  74.     }
  75.     }
  76. }
  77.  
  78.  
  79. /*
  80.  *    We are the parent process, so read from user and
  81.  *    send to remote, until disconnect character recieved.
  82.  */
  83.  
  84. static VOID HostOut ()
  85. {
  86.     auto char c;
  87.     
  88.     DBUG_ENTER ("HostOut");
  89.     c = NULL;
  90.     (VOID) printf ("Connected.\r\n");
  91.     HostRaw ();
  92.     (VOID) read (0, &c, 1);
  93.     while (c != escchr) {
  94.     (VOID) write (remfd, &c, 1);
  95.     c = NULL;
  96.     (VOID) read (0, &c, 1);
  97.     }
  98.     HostCooked ();
  99.     (VOID) printf ("\nDisconnected.\n");
  100.     DBUG_VOID_RETURN;
  101. }
  102.